package com.cole.gx095.controller;

import com.cole.gx095.Repository.AttachRepository;
import com.cole.gx095.Repository.PurBillgoodsRepository;
import com.cole.gx095.Repository.PurchasebillRepository;
import com.cole.gx095.Repository.PurchasecontractRepository;
import com.cole.gx095.domain.PurBillTableData;
import com.cole.gx095.service.PurQueryService;
import com.cole.gx095.entity.PurBillgoods;
import com.cole.gx095.entity.Purchasebill;
import com.cole.gx095.entity.Purchasecontract;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.text.ParseException;
import java.util.List;

@SpringBootTest
@Transactional
public class purchaseContract {

    @Autowired
    PurchasecontractRepository purchasecontractRepository;

    @Autowired
    AttachRepository attachRepository;
    @Autowired
    PurQueryService purQueryService;

    @Autowired
    PurchasebillRepository purchasebillRepository;
    @Autowired
    PurBillgoodsRepository purBillgoodsRepository;
    @Test
    void list(){
        Page<Purchasecontract> page1 = purchasecontractRepository.findAll(PageRequest.of(0, 5));
        Purchasecontract purchasecontract = null;
    }
    @Test
    void textTime() throws ParseException {
        Purchasecontract purchasecontract1 = new Purchasecontract();
        Purchasecontract purchasecontract2 = new Purchasecontract();
        Purchasecontract purchasecontract3 = new Purchasecontract();
//        purchasecontract1.setContractDate(2019-01-03);
//      new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse("2019-01-03 10:59:27") 为 java.util.Date
//        purchasecontract2.setContractDate(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse("2019-01-03 10:59:27"));

        System.out.println("purchasecontract2 = " + purchasecontract2);
    }

    @Test
    void textgetBillById(){
        Purchasecontract byId = purchasecontractRepository.getById(1);
        purchasebillRepository.findAllBycontractNum(byId.getContractNum());
        System.out.println("byId.getContractNum() = " + byId.getContractNum());
        List<PurBillgoods> allBycontractNum = purBillgoodsRepository.findAllBycontractNum(byId.getContractNum());
        for (PurBillgoods purBillgoods : allBycontractNum) {
            System.out.println("purBillgoods = " + purBillgoods);
        }

        List<PurBillTableData> purBillTableDataList = new ArrayList<>();
        for (PurBillgoods purBillgoods : allBycontractNum) {
            Purchasebill purchasebill = purchasebillRepository.getById(purBillgoods.getBillId());
            PurBillTableData purBillTableData = new PurBillTableData();
            purBillTableData.setBillNum(purchasebill.getBillNum());
            purBillTableData.setCreateDate(purchasebill.getCreateDate());
            purBillTableData.setBillAccount(purchasebill.getBillAccount());
            purBillTableData.setAttachCount(purchasebill.getAttachCount());
            purBillTableData.setUpdateCountbill(purchasebill.getUpdateCount());
            purBillTableData.setTypeName(purBillgoods.getTypeName());
            purBillTableData.setGoodsName(purBillgoods.getGoodsName());
            purBillTableData.setModle(purBillgoods.getModle());
            purBillTableData.setGoodsAccount(purBillgoods.getGoodsAccount());
            purBillTableData.setGoodsUnitPrice(purBillgoods.getGoodsUnitPrice());
            purBillTableData.setGoodsSumPrice(purBillgoods.getGoodsSumPrice());
            purBillTableData.setUsedAccount(purBillgoods.getUsedAccount());
            purBillTableData.setBillType(purchasebill.getBillType());
            purBillTableData.setCreateAdminTrueName(purchasebill.getCreateAdminTrueName());
            purBillTableDataList.add(purBillTableData);
        }
        for (PurBillTableData purBillTableData : purBillTableDataList) {
            System.out.println("purBillTableData = " + purBillTableData);
        }

    }
}
